local skel = fk.CreateSkill {
  name = "lb_zero__luoqian",
  tags = { Skill.Combo, Skill.Switch },
}

Fk:loadTranslationTable {
  ["lb_zero__luoqian"] = "络千",
  [":lb_zero__luoqian"] = "<b><a href='#ComboSkill-href'>连招技</a></b>（牌+牌，均与你使用过的牌名阳：不同；阴：相同），你可以" ..
      "阳：视为使用一张雷【杀】；阴：移动场上的一张牌。",

  [":lb_zero__luoqian_yang"] = "<b><a href='#ComboSkill-href'>连招技</a></b>（牌+牌，均与你使用过的牌名<font color='#E0DB2F'>阳：不同；</font>阴：相同），你可以" ..
      "<font color='#E0DB2F'>阳：视为使用一张雷【杀】；</font>阴：移动场上的一张牌。",
  [":lb_zero__luoqian_yin"] = "<b><a href='#ComboSkill-href'>连招技</a></b>（牌+牌，均与你使用过的牌名阳：不同；<font color='#E0DB2F'>阴：相同</font>），你可以" ..
      "阳：视为使用一张雷【杀】；<font color='#E0DB2F'>阴：移动场上的一张牌。</font>",

  ["@[lb_zero__luoqian]lb_zero__luoqian"] = "络千",

  ["#lb_zero__luoqian-slash"] = "络千：你可以视为使用一张雷【杀】",
  ["#lb_zero__luoqian-move"] = "络千：你可以移动场上一张牌",

  ["#lb_zero__luoqian-combo"] = "连招进度",
  ["#lb_zero__luoqian-use"] = "已使用牌名",


  ["$lb_zero__luoqian1"] = "奉命缉拿。",
  ["$lb_zero__luoqian2"] = "就地，正法！",
  ["$lb_zero__luoqian3"] = "需惩戒一番。",
}

Fk:addQmlMark {
  name = "lb_zero__luoqian",
  how_to_show = function(_, value, player)
    if type(value) == "table" then
      if type(value.combo) == "table" then
        local mark = {}
        for _, val in ipairs(value.combo) do
          local name = Fk:translate(val[2])
          --[[
          if val[2]:startsWith("log_") then
            name = "<font color='red'>" .. name .. "</font>"
          end
          --]]
          table.insert(mark, name)
        end
        if #mark > 0 then
          return table.concat(mark, "/")
        end
      end
      if type(value.all_name) == "table" and #value.all_name > 0 then
        return tostring(#value.all_name)
      end
    end
    return " "
  end,
  qml_data = function(_, value, player)
    if type(value) == "table" then
      local list = {}
      if type(value.combo) == "table" then
        local mark = {}
        for _, val in ipairs(value.combo) do
          table.insert(mark, val[1])
        end
        if #mark > 0 then
          table.insert(mark, 1, "#lb_zero__luoqian-combo")
          table.insert(list, mark)
        end
      end
      if type(value.all_name) == "table" and #value.all_name > 0 then
        local all_name = table.simpleClone(value.all_name)
        table.insert(all_name, 1, "#lb_zero__luoqian-use")
        table.insert(list, all_name)
      end
      return list
    end
  end,
  qml_path = function(name, value, player)
    return ((type(value.all_name) == "table" and #value.all_name > 0) or (type(value.combo) == "table" and #value.combo > 0)) 
    and "packages/lb_kill_zero/qml/LuoQianCombo" or ""
  end,
}

skel:addEffect(fk.CardUsing, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(skel.name) and
        data.extra_data and data.extra_data.combo_skill and data.extra_data.combo_skill[skel.name]
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    if player:getSwitchSkillState(skel.name) == fk.SwitchYang then
      local use = room:askToUseVirtualCard(player, {
        name = "thunder__slash",
        skill_name = skel.name,
        skip = true,
        prompt = "#lb_zero__luoqian-slash",
      })
      if use then
        event:setCostData(self, { use = use })
        return true
      end
    else
      local tos = room:askToChooseToMoveCardInBoard(player, {
        skill_name = skel.name,
        prompt = "#lb_zero__luoqian-move",
      })
      if #tos > 0 then
        event:setCostData(self, { tos = tos })
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local list = player:getTableMark("@[lb_zero__luoqian]lb_zero__luoqian")
    list.combo = {}
    room:setPlayerMark(player, "@[lb_zero__luoqian]lb_zero__luoqian", list)
    local use = event:getCostData(self).use
    if use then
      room:useCard(use)
    else
      local tos = event:getCostData(self).tos
      room:askToMoveCardInBoard(player, {
        target_one = tos[1],
        target_two = tos[2],
        skill_name = skel.name,
      })
    end
  end,
})

skel:addEffect(fk.AfterCardUseDeclared, {
  can_refresh = function(self, event, target, player, data)
    return target == player and player:hasSkill(skel.name, true)
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    local list = player:getTableMark("@[lb_zero__luoqian]lb_zero__luoqian")
    local all_name = list.all_name or {}
    local combo = list.combo or {}
    local isUse = table.contains(all_name, data.card.trueName)
    local state = isUse and "yin" or "yang"
    if player:getSwitchSkillState(skel.name, false, true) == state then
      state = "log_" .. state
    end
    table.insert(combo, { data.card.trueName, state })
    while #combo > 2 do
      table.remove(combo, 1)
    end
    if #combo == 2 and combo[1][2]:startsWith("log_") and combo[2][2]:startsWith("log_") then
      data.extra_data = data.extra_data or {}
      data.extra_data.combo_skill = data.extra_data.combo_skill or {}
      data.extra_data.combo_skill[skel.name] = true
    end
    table.insertIfNeed(all_name, data.card.trueName)
    room:setPlayerMark(player, "@[lb_zero__luoqian]lb_zero__luoqian", { all_name = all_name, combo = combo })
  end,
})

skel:addLoseEffect(function(self, player, is_death)
  player.room:setPlayerMark(player, "@[lb_zero__luoqian]lb_zero__luoqian", 0)
end)

return skel
